
class DateFormat {
    constructor() {
        this.date = new Date(Date.now());
    }
    minus (days) {
        this.date.setDate(this.date.getDate() - days);
        return this;
    }
    format (str = 'yyyyMMdd') {
        const year = this.date.getFullYear();
        const month = String(this.date.getMonth() + 1).padStart(2, '0');
        const day = String(this.date.getDate()).padStart(2, '0');
        const hour = String(this.date.getHours()).padStart(2, '0');
        const minute = String(this.date.getMinutes()).padStart(2, '0');
        const second = String(this.date.getSeconds()).padStart(2, '0');

        return str
            .replace(/yyyy/g, year)
            .replace(/MM/g, month)
            .replace(/dd/g, day)
            .replace(/HH/g, hour)
            .replace(/mm/g, minute)
            .replace(/ss/g, second);
    }
}


module.exports = DateFormat